﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Entity;

namespace ETL.DataAccess
{
    public class ProjectCategoryRepository
    {
        public IEnumerable<project_categories> GetProjectCategories(int? projectId)
        {
            if (projectId.HasValue)
            {
                var db = new ETLDataEntities();
                var result = from s in db.project_categories where s.c_project == projectId && s.c_active == true orderby  s.c_order select s;
                return result;
            }
            else return null;
        }

        public project_categories GetProjectCategory(int? projectId, int? categoryId)
        {
            if (projectId.HasValue && categoryId.HasValue)
            {
                var db = new ETLDataEntities();
                var result = (from s in db.project_categories where s.c_project == projectId select s);
                if (result.Count() > 0)
                {
                    return result.First();
                }
                else
                {
                    return null;
                }
            }
            else return null;
        }
    }
}
